package day04;

import java.util.Arrays;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/4/12
 */
public class ArraysDemo {
    public static void main(String[] args) {
        int[] arr={1,31,15,27,9};
        System.out.println(Arrays.toString(arr));

        System.out.println("-------------------排序 & 二分搜索---------------------");

        Arrays.sort(arr);
        System.out.println("排序："+Arrays.toString(arr));

        //第一个参数：数组  第二个参数：查询的数
        int index1 = Arrays.binarySearch(arr, 7);
        System.out.println("index:"+index1);
        //第一个参数：数组  第二个参数：查询的起始下标  第三个参数：查询的终止下标（取不到）  第四个参数：查询的数
        int index2 = Arrays.binarySearch(arr, 2 ,4,27);
        System.out.println("index:"+index2);

        System.out.println("------------------拷贝 & 赋值------------------------");
        int[] brr = {12 , 34 , 7 , 18 ,26 };

        //拷贝
        int[] brr1=Arrays.copyOf(brr, brr.length);
        brr1[1] = 44;
        System.out.println("拷贝 brr:"+Arrays.toString(brr));
        System.out.println("拷贝 brr1："+Arrays.toString(brr1));
        System.out.println("equals:"+Arrays.equals(brr , brr1));
        System.out.println("==:"+(brr == brr1));

        //赋值
        int[] brr2=brr;
        brr2[2] = 55;
        System.out.println("赋值 brr："+Arrays.toString(brr));
        System.out.println("赋值 brr2："+Arrays.toString(brr2));
        System.out.println("equals:"+Arrays.equals(brr , brr2));
        System.out.println("==:"+(brr == brr2));

        //扩容
        System.out.println("-------------------扩容-----------------------");
        int[] crr =Arrays.copyOf(brr, brr.length*2);
        System.out.println(Arrays.toString(crr));
        System.out.println(crr.length);
    }
}
